/*
========================================================================
 Name        : FRamI_UIMainContainer.cpp
 Author      : Lenka Litvova
 Copyright   : Copyright belongs to Lenka Litvova
 Description : 
========================================================================
*/
// [[[ begin generated region: do not modify [Generated System Includes]
#include <barsread.h>
#include <eikimage.h>
#include <eikenv.h>
#include <aknviewappui.h>
#include <eikappui.h>
#include <akniconutils.h>
#include <FRamI_UI.mbg>
#include <FRamI_UI.rsg>
// ]]] end generated region [Generated System Includes]

// [[[ begin generated region: do not modify [Generated User Includes]
#include "FRamI_UIMainContainer.h"
#include "FRamI_UIMainContainerView.h"
#include "FRamI_UI.hrh"
#include "FRamI_UIMainContainer.hrh"
#include "FRamI_UISettingList.hrh"
#include "FRamI_UIUsersList.hrh"
// ]]] end generated region [Generated User Includes]

// [[[ begin generated region: do not modify [Generated Constants]
_LIT( KFRamI_UIFile, "\\resource\\apps\\FRamI_UI.mbm" );
// ]]] end generated region [Generated Constants]

/**
 * First phase of Symbian two-phase construction. Should not 
 * contain any code that could leave.
 */
CFRamI_UIMainContainer::CFRamI_UIMainContainer()
	{
	// [[[ begin generated region: do not modify [Generated Contents]
	iBackgroundImage = NULL;
	// ]]] end generated region [Generated Contents]
	
	}
/** 
 * Destroy child controls.
 */
CFRamI_UIMainContainer::~CFRamI_UIMainContainer()
	{
	// [[[ begin generated region: do not modify [Generated Contents]
	delete iBackgroundImage;
	iBackgroundImage = NULL;
	// ]]] end generated region [Generated Contents]
	
	}
				
/**
 * Construct the control (first phase).
 *  Creates an instance and initializes it.
 *  Instance is not left on cleanup stack.
 * @param aRect bounding rectangle
 * @param aParent owning parent, or NULL
 * @param aCommandObserver command observer
 * @return initialized instance of CFRamI_UIMainContainer
 */
CFRamI_UIMainContainer* CFRamI_UIMainContainer::NewL( 
		const TRect& aRect, 
		const CCoeControl* aParent, 
		MEikCommandObserver* aCommandObserver )
	{
	CFRamI_UIMainContainer* self = CFRamI_UIMainContainer::NewLC( 
			aRect, 
			aParent, 
			aCommandObserver );
	CleanupStack::Pop( self );
	return self;
	}

/**
 * Construct the control (first phase).
 *  Creates an instance and initializes it.
 *  Instance is left on cleanup stack.
 * @param aRect The rectangle for this window
 * @param aParent owning parent, or NULL
 * @param aCommandObserver command observer
 * @return new instance of CFRamI_UIMainContainer
 */
CFRamI_UIMainContainer* CFRamI_UIMainContainer::NewLC( 
		const TRect& aRect, 
		const CCoeControl* aParent, 
		MEikCommandObserver* aCommandObserver )
	{
	CFRamI_UIMainContainer* self = new ( ELeave ) CFRamI_UIMainContainer();
	CleanupStack::PushL( self );
	self->ConstructL( aRect, aParent, aCommandObserver );
	return self;
	}
			
/**
 * Construct the control (second phase).
 *  Creates a window to contain the controls and activates it.
 * @param aRect bounding rectangle
 * @param aCommandObserver command observer
 * @param aParent owning parent, or NULL
 */ 
void CFRamI_UIMainContainer::ConstructL( 
		const TRect& aRect, 
		const CCoeControl* aParent, 
		MEikCommandObserver* aCommandObserver )
	{
	if ( aParent == NULL )
	    {
		CreateWindowL();
	    }
	else
	    {
	    SetContainerWindowL( *aParent );
	    }
	iFocusControl = NULL;
	iCommandObserver = aCommandObserver;
	InitializeControlsL();
	SetRect( aRect );
	ActivateL();
	// [[[ begin generated region: do not modify [Post-ActivateL initializations]
	// ]]] end generated region [Post-ActivateL initializations]
	
	}
			
/**
* Return the number of controls in the container (override)
* @return count
*/
TInt CFRamI_UIMainContainer::CountComponentControls() const
	{
	return ( int ) ELastControl;
	}
				
/**
* Get the control with the given index (override)
* @param aIndex Control index [0...n) (limited by #CountComponentControls)
* @return Pointer to control
*/
CCoeControl* CFRamI_UIMainContainer::ComponentControl( TInt aIndex ) const
	{
	// [[[ begin generated region: do not modify [Generated Contents]
	switch ( aIndex )
		{
		case EBackgroundImage:
			return iBackgroundImage;
		}
	// ]]] end generated region [Generated Contents]
	
	// handle any user controls here...
	
	return NULL;
	}
				
/**
 *	Handle resizing of the container. This implementation will lay out
 *  full-sized controls like list boxes for any screen size, and will layout
 *  labels, editors, etc. to the size they were given in the UI designer.
 *  This code will need to be modified to adjust arbitrary controls to
 *  any screen size.
 */				
void CFRamI_UIMainContainer::SizeChanged()
	{
	CCoeControl::SizeChanged();
	LayoutControls();
	// [[[ begin generated region: do not modify [Generated Contents]
			
	// ]]] end generated region [Generated Contents]
	
	}
				
// [[[ begin generated function: do not modify
/**
 * Layout components as specified in the UI Designer
 */
void CFRamI_UIMainContainer::LayoutControls()
	{
	iBackgroundImage->SetExtent( TPoint( 0, 0 ), TSize( 240, 222 ) );
	}
// ]]] end generated function

/**
 *	Handle key events.
 */				
TKeyResponse CFRamI_UIMainContainer::OfferKeyEventL( 
		const TKeyEvent& aKeyEvent, 
		TEventCode aType )
	{
	// [[[ begin generated region: do not modify [Generated Contents]
	
	// ]]] end generated region [Generated Contents]
	
	if ( iFocusControl != NULL
		&& iFocusControl->OfferKeyEventL( aKeyEvent, aType ) == EKeyWasConsumed )
		{
		return EKeyWasConsumed;
		}
	return CCoeControl::OfferKeyEventL( aKeyEvent, aType );
	}
				
// [[[ begin generated function: do not modify
/**
 *	Initialize each control upon creation.
 */				
void CFRamI_UIMainContainer::InitializeControlsL()
	{
	iBackgroundImage = new ( ELeave ) CEikImage;
		{
		CFbsBitmap *bitmap, *mask;
		AknIconUtils::CreateIconL( bitmap, mask,
				KFRamI_UIFile, EMbmFrami_uiBackground, -1 );
		AknIconUtils::SetSize( bitmap, TSize( 240, 222 ), EAspectRatioPreserved );
		iBackgroundImage->SetPicture( bitmap );
		}
	iBackgroundImage->SetAlignment( EHCenterVTop );
	
	}
// ]]] end generated function

/** 
 * Handle global resource changes, such as scalable UI or skin events (override)
 */
void CFRamI_UIMainContainer::HandleResourceChange( TInt aType )
	{
	CCoeControl::HandleResourceChange( aType );
	SetRect( iAvkonViewAppUi->View( TUid::Uid( EFRamI_UIMainContainerViewId ) )->ClientRect() );
	// [[[ begin generated region: do not modify [Generated Contents]
	// ]]] end generated region [Generated Contents]
	
	}
				
/**
 *	Draw container contents.
 */				
void CFRamI_UIMainContainer::Draw( const TRect& aRect ) const
	{
	// [[[ begin generated region: do not modify [Generated Contents]
	CWindowGc& gc = SystemGc();
	gc.Clear( aRect );
	
	// ]]] end generated region [Generated Contents]
	
	}
				
